package cn.yeziji.forum.controller;

import cn.yeziji.forum.common.ForumResult;
import cn.yeziji.forum.dao.intf.ForumDetailsDao;
import cn.yeziji.forum.dao.intf.ForumSpecialColumnDao;
import cn.yeziji.forum.dao.intf.ForumTagsDao;
import cn.yeziji.forum.dao.intf.ForumUserDao;
import cn.yeziji.forum.dto.details.ForumDetailPagingDTO;
import cn.yeziji.forum.dto.user.UserFocusOrFansListPagingDTO;
import cn.yeziji.forum.service.StaticsService;
import cn.yeziji.forum.utils.ForumResultUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 个人中心控制器
 *
 * @author gzkemays
 * @since 2022/11/28 6:14 PM
 */
@RestController
@RequestMapping("/centre")
public class ForumCentreController {
  @Resource ForumUserDao userDao;
  @Resource ForumTagsDao tagsDao;
  @Resource ForumDetailsDao detailsDao;

  @Resource StaticsService staticsService;
  @Resource ForumSpecialColumnDao specialDao;

  @GetMapping("/dlist")
  public ForumResult detailList(@Validated ForumDetailPagingDTO dto) {
    dto.setDelete(false);
    dto.setTempSave(false);
    if (dto.getCollection() != null || dto.getGood() != null) {
      return ForumResultUtils.ok(detailsDao.getUserCollectionOrGoodDetails(dto));
    }
    return ForumResultUtils.ok(detailsDao.getList(dto));
  }

  @PostMapping("/focusOrFans")
  public ForumResult getFocusOrFansCentre(@RequestBody UserFocusOrFansListPagingDTO pagingDTO) {
    pagingDTO.setFocus(true);
    pagingDTO.setFans(false);
    pagingDTO.setPage(0);
    pagingDTO.setLimit(4);
    return ForumResultUtils.ok(userDao.getFocusOrFansUserMsg(pagingDTO).getData());
  }

  @PostMapping("/special")
  public ForumResult getSpecialByNickname(String nickname) {
    return ForumResultUtils.ok(specialDao.getSpecialsByNickname(nickname));
  }

  @PostMapping("/tags")
  public ForumResult getTagsByNickname(String nickname) {
    return ForumResultUtils.ok(tagsDao.getTagsByNickname(nickname));
  }

  @PostMapping("/statics")
  public ForumResult statics7DaysList(String nickname) {
    return ForumResultUtils.ok(staticsService.statics7DaysList(nickname));
  }
}
